//
//  LYMeViewController.swift
//  WeChat
//
//  Created by mac on 2018/7/24.
//  Copyright © 2018年 RRC. All rights reserved.
//

import UIKit


class LYMeViewController: UIViewController {
    
    let headCellIdentifier:String = "leadCellIdentifier"
    let footerCellIdentifier:String = "trailCellIdentifier"
    
    var listTableView:UITableView!
    fileprivate let itemDataSource:[[(name:String, iconImage:UIImage?)]] = [
        [
            ("", nil)
        ],
        [
            ("相册", LYAsset.MoreMyAlbum.image),
            ("收藏", LYAsset.MoreMyFavorites.image),
            ("钱包", LYAsset.MoreMyBankCard.image),
            ("优惠券", LYAsset.MyCardPackageIcon.image)
        ],
        [
            ("表情", LYAsset.MoreExpressionShops.image)
        ],
        [
            ("设置", LYAsset.MoreSetting.image)
        ]
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        self.title = "我"
        self.view.backgroundColor = UIColor.viewBackgroundColor
        
        listTableView = UITableView()
        listTableView.backgroundColor = UIColor.init(ts_hexString: "#EFEFF4")
        listTableView.estimatedRowHeight = 0
        listTableView.estimatedSectionFooterHeight = 0
        listTableView.estimatedSectionHeaderHeight = 0
        listTableView.delegate = self
        listTableView.dataSource = self
        self.view.addSubview(listTableView)
        listTableView.snp.makeConstraints { (make) in
            make.edges.equalTo(0)
        }
        listTableView.register(LYMeAvatarTableViewCell.self, forCellReuseIdentifier: headCellIdentifier)
        listTableView.register(TSImageTextTableViewCell.self, forCellReuseIdentifier: footerCellIdentifier)
        listTableView.tableFooterView = UIView()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

// MARK: -  UITableViewDelegate
extension LYMeViewController: UITableViewDelegate{
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0 {
            return 88.0
        }else{
            return 44.0
        }
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if section == 0 {
            return 15
        }else{
            return 20
        }
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.000001
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }
    
}

// MARK: - UITableViewDataSource
extension LYMeViewController: UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return itemDataSource.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        let rows = itemDataSource[section]
        return rows.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == 0 {
            let cell:LYMeAvatarTableViewCell = tableView.dequeueReusableCell(withIdentifier: headCellIdentifier) as! LYMeAvatarTableViewCell
            
            return cell
        }else{
            let cell:TSImageTextTableViewCell = tableView.dequeueReusableCell(withIdentifier: footerCellIdentifier) as! TSImageTextTableViewCell
            let item = itemDataSource[indexPath.section][indexPath.row]
            cell.iconImageView.image = item.iconImage
            cell.titleLabel.text = item.name
            return cell
        }
    }
    
    
}


